import uuid
import random
import os
import sys
from pkg.driver import all_driver


def cur_file_dir():
    path = sys.path[0]
    if os.path.isdir(path):
        return path
    elif os.path.isfile(path):
        return os.path.dirname(path)


g_curr_user = tuple()
g_temp_dir = cur_file_dir() + '/data/temp'
g_http_catch_dir = cur_file_dir() + '/data/temp/catch'
g_db_dir = cur_file_dir() + '/data/db'
g_download_dir = cur_file_dir() + '/data/download'
g_db_name = g_db_dir + '/SkyFire.db'
g_token = ''
g_is_recording = False
g_recv_obj=all_driver.recv_obj()
g_driver_obj=all_driver.driver_obj()






g_db_user_build = 'CREATE TABLE IF NOT EXISTS USER (' \
                  'id VARCHAR (64) NOT NULL,' \
                  'nick VARCHAR(64) NOT NULL, ' \
                  'sex INT NOT NULL DEFAULT 0,' \
                  'birth DATE NOT NULL' \
                  ')'

g_db_voice_build = 'CREATE TABLE IF NOT EXISTS VOICE(' \
                   'text VARCHAR (1024) NOT NULL ,' \
                   'bin BLOB' \
                   ')'


def mk_all_dir():
    if not os.path.exists(g_temp_dir):
        os.makedirs(g_temp_dir)
    if not os.path.exists(g_http_catch_dir):
        os.makedirs(g_http_catch_dir)
    if not os.path.exists(g_db_dir):
        os.makedirs(g_db_dir)
    if not os.path.exists(g_download_dir):
        os.makedirs(g_download_dir)

mk_all_dir()


def get_mac_address():
    mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
    return ":".join([mac[e:e+2] for e in range(0,11,2)])


def get_temp_file_name(ext):
    return ''.join(random.sample('0123456789zyxwvutsrqponmlkjihgfedcba', 20))+'.'+ext